package cn.usian.basicInformation.city.service.impl;

import cn.usian.basicInformation.city.mapper.CityGradeMapper;
import cn.usian.basicInformation.city.mapper.CityMapper;
import cn.usian.basicInformation.city.service.ICityService;
import cn.usian.dto.basicInformation.city.BaseCityGradeManageDto;
import cn.usian.pojo.basicInformation.city.BaseCityGrade;
import cn.usian.pojo.basicInformation.city.BaseCityGradeManage;
import cn.usian.vo.basicInformation.city.BaseCityGradeManageVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class CityServiceImpl implements ICityService{
    @Autowired
    private CityMapper cityMapper;

    @Autowired
    private CityGradeMapper cityGradeMapper;

    @Override
    public PageInfo<BaseCityGradeManageVo> list(BaseCityGradeManageDto cityGradeManageDto) {
        PageHelper.startPage(cityGradeManageDto.getPageNum(),cityGradeManageDto.getPageSize());
        List<BaseCityGradeManageVo> list = cityMapper.list(cityGradeManageDto.getCityGradeId(), cityGradeManageDto.getCityName());
        log.info("list:{}",list);
        PageInfo<BaseCityGradeManageVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<BaseCityGrade> cityGradeList() {
        return cityGradeMapper.cityGradeList();
    }


    @Override
    public void save(BaseCityGradeManage baseCityGradeManage) {
        if(baseCityGradeManage.getCityGradeId() == 0){
            baseCityGradeManage.setCityGradeId(3);
        }
        baseCityGradeManage.setUpdateId(1);
        baseCityGradeManage.setUpdateTime(new Date());
        cityMapper.update(baseCityGradeManage);
    }
}
